<?php

namespace app\admin\model;

use think\exception\ValidateException;
use think\Model;

class WechatPaymentConfig extends Model
{



    public function getStoreInfo(): \think\model\relation\HasOne
    {

        return    $this->hasOne(Store::class,'id','store_id')->bind(['store_name'=>'name']);
    }
    public static function getlists(){

       return self::with(['getStoreInfo'])->where(['store_id'=>session('store_id')])->select();

    }

    public static function insertconfig($add){
        try {

            self::create($add);

            return array(
                'code' => 200,
                'msg' => '成功!',
            );

        } catch (ValidateException $e) {
            // 验证失败 输出错误信息
            return $e->getError();
        }

    }

    public static function modifyconfig($add)
    {
        try {
            $result = self::where(['id' => input('id')])->save($add);

            if (!empty($result)) {
                return array(
                    'code' => 200,
                    'msg' => '成功!',
                );
            } else {
                return array(
                    'code' => 40002,
                    'msg' => '成功!',
                );
            }

        } catch (ValidateException $e) {
            // 验证失败 输出错误信息

            return $e->getError();
        }
    }

}